package com.mr.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.mr.filter.FirstFilter;
import com.mr.filter.SecondFilter;
import com.mr.filter.ThirdFilter;

@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean<FirstFilter> getFilter1() {
        FilterRegistrationBean<FirstFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new FirstFilter());
        bean.addUrlPatterns("/*");
        bean.setOrder(4);
        bean.setName("lisi");
        bean.setEnabled(false);
        System.out.println("过滤器1的状态"+bean.isEnabled());
        System.out.println("过滤器1的优先级"+bean.getOrder());
        return bean;
    }

    @Bean
    public FilterRegistrationBean<SecondFilter> getFilter2() {
        FilterRegistrationBean<SecondFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new SecondFilter());
        bean.addUrlPatterns("/*");
        bean.setOrder(2);
        System.out.println("过滤器2的状态"+bean.isEnabled());
        System.out.println("过滤器2的优先级"+bean.getOrder());
        return bean;
    }

    @Bean
    public FilterRegistrationBean<ThirdFilter> getFilter3() {
        FilterRegistrationBean<ThirdFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new ThirdFilter());
        bean.addUrlPatterns("/*");
        bean.setOrder(1);
        System.out.println("过滤器3的状态"+bean.isEnabled());
        System.out.println("过滤器3的优先级"+bean.getOrder());
        return bean;
    }
}
